<?php
namespace Home\Controller;
use Think\Controller;
use Home\Model\DepartmentModel;
header("Content-Type: text/html;charset=utf-8");
class DepartmentController extends Controller {
    
    public function index(){
        $this->display('index');
    }

    public function account(){
		if(IS_POST){
			$rules=array(
			array('address','/^[\x{4e00}-\x{9fa5}]+$/u',2,'所在地必须填写中文名'),
			array('phone','checkPhone','手机号码格式不正确',2,'function'),
			array('phone','number',2,'手机号码格式不正确'),
	
			);
			$User= M('user_department');
			 if (!$User->validate($rules)->create()){
				  exit($User->getError());
			}else{    
			$result = $User->where('user_id='.session('id'))->save(I('post.'));
            var_dump(I('post.'));
            if($result){
                $this->success('修改成功', '/Bailey/index.php/Home/Department/account', 1);
            }else{
                $this->success('没有更改内容', '/Bailey/index.php/Home/Department/account', 1);
            }
			
		}
		}	
        else{
		
			$find = array('user_id' => session('id') );
            $data['department'] = M('user_department')->join('RIGHT JOIN user ON user_department.user_id = user.id' )->where($find)->find();
            $this->assign($data);
            $this -> display('account');
			}
		}		
   
     




    // public function register(){
    //     if(I('post.submit')==1){
    //         $data['username'] = I('post.username');
    //         if($data = M('teacher')->where($data)->find()){
    //             $this->error('用户已经存在');
    //         }
    //         $data = M('teacher')->data(I('post.'))->add();
    //         if($data) $this->success('注册成功', '/Bailey/index.php/Home/Index/index', 1);
    //     }else{
    //         $this->display('register');
    //     
         
    // }
    // public function login(){
    //     if(session('id')) $this->redirect('/Home/Index/index');
    //      if (I('post.login') == 1) {
    //         $data['username'] = I('post.username');
    //         $data['password'] = I('post.password');
    //         $data = M('teacher')->where($data)->find();
    //         if ($data) {
    //             session('username', $data['username']);
    //             session('id', $data['teacher_id']);
    //             $this->success('操作完成', '/Bailey/index.php/Home/Index/index', 3);
    //         } else {
    //             echo 'false';
    //         }
    //     } else {
    //         $this->display('login');
    //     }
    // }
    // public function delete(){
        
    // }  


}